#ifndef DATABASEMODEL_H
#define DATABASEMODEL_H

#include <QSqlTableModel>

class DatabaseModel : public QSqlTableModel
{
    Q_OBJECT

public:
    explicit DatabaseModel(QObject *parent = 0);

    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;

    bool addToday();
    bool updateToday(const QTime& i_begin,
                     const QTime& i_break);
    bool updateTodaysEnd(int i_msecsToAdd);
    int updateTisowareData(QString& o_errorText, const QDate &i_dateFrom, const QDate &i_dateTo);
    QDate minimumDate() const;
    QDate maximumDate() const;
    int sumTisoware() const;
    int sumWork() const;

    enum Columns
    {
        ID,
        Date,
        Begin,
        End,
        Break,
        Comment,
        TwTime,
        Duration,
        Status,
        Weekday,
    };

    static const QColor COLOR_OK;
    static const QColor COLOR_NO_TW;
    static const QColor COLOR_TOOMUCH_TW;
    static const QColor COLOR_TOOLESS_TW;

private:
    enum TwStatus
    {
        TwOk,
        TwNo,
        TwTooMuch,
        TwTooLess,
        TwDefault,
    };

    TwStatus calcStatus(int i_row) const;
};

#endif // DATABASEMODEL_H
